<template>
  <j-select-user-by-dep v-model="newValue" :disabled="disabled" :multi="record.options.multiple"></j-select-user-by-dep>
</template>
<script>
import { mapState } from 'vuex'
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
export default {
  name: 'User',
  props: ['record', 'value', 'disabled'],
  components: {
    JSelectUserByDep
  },
  data() {
    return {
      newValue: ''
    }
  },
  watch: {
    value(newValue) { // 用户值改变时   获取用户真实姓名
      this.newValue = newValue
    },
    'record.options.defaultValue'(newValue) {
      if (newValue === '${username}' || newValue === '${realname}') {
        this.$emit('change', this.username)
      } else {
        this.$emit('change', newValue)
      }
    },
    newValue(value) {
      this.$emit('change', value)
    }
  },
  computed: {
    ...mapState({
      username: state => state.user.username
    })
  },
  mounted() {
    const defaultValue = this.record.options.defaultValue
    if (defaultValue === '${username}' || defaultValue === '${realname}') {
      this.$emit('change', this.username)
    }
  }
}
</script>
